package exception;

public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了");
        try {
            //String str = null;

            String str2 = "abcdefgh";

            System.out.println(str2.length());
            System.out.println(str2.charAt(3));
            System.out.println(Integer.parseInt(str2));
//        }catch (NullPointerException e){
//            System.out.println("空指针异常，并且处理完毕了");
//        }catch (StringIndexOutOfBoundsException e){
//            System.out.println("字符串下标越界，并处理完毕了");
//        }


        } catch (NullPointerException | StringIndexOutOfBoundsException e) {
            System.out.println("出现空指针或下标越界，并用相同方式处理完毕了");
        } catch (Exception e) {
            System.out.println("反正就是出了一个错误！");
        }

        System.out.println("程序结束了");
    }


}
